home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Documents / JAVA Programming / examples / 11 / ThreadDemo.java < prev   
Encoding:
Java Source  |  2000-09-08  |  705 b   |  30 lines

  1. class ThreadDemo implements Runnable {
  2. ThreadDemo() {
  3. Thread ct = Thread.currentThread();
  4. System.out.println("currentThread: " + ct);
  5. Thread t = new Thread(this, "Demo Thread");
  6. System.out.println("Thread created: " + t);
  7. t.start();
  8. try {
  9. Thread.sleep(3000);
  10. catch (InterruptedException e) { 
  11. System.out.println("interrupted");
  12. }
  13. System.out.println("exiting main thread");
  14. }
  15. public void run() { 
  16. try {
  17. for (int i = 5; i > 0; i--) { 
  18. System.out.println("" + i);
  19. Thread.sleep(1000);
  20. } } 
  21. catch (InterruptedException e) {
  22. System.out.println("child interrupted");
  23. System.out.println("exiting child thread");
  24. }
  25. public static void main(String args[]) { 
  26. new ThreadDemo();
  27. } }
  28.